/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.cggveritas.crewintranet.jms.utils.converter;


import fr.cggveritas.crewintranet.jms.dao.jpacontroller.CvCompagnieJpaController;
import fr.cggveritas.crewintranet.jms.dao.jpacontroller.CvVehiculeJpaController;
import fr.cggveritas.crewintranet.jms.entities.CvCompagnie;
import fr.cggveritas.crewintranet.jms.entities.CvVehicule;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

/**
 *
 * @author ly01
 */
public class VehiculeConverter implements javax.faces.convert.Converter{
    
    private CvVehiculeJpaController cvVehiculeJpaController;
    
    public VehiculeConverter(){
        cvVehiculeJpaController = new CvVehiculeJpaController();
    }
    
    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
        //throw new UnsupportedOperationException("Not supported yet.");
        //Employe employe=new Employe(Long.parseLong(string));
//       System.out.println("value getAsObject : "+value);
//       System.out.println("lookupEmployeFacadeLocal() : "+lookupEmployeFacadeLocal());
       try {
         CvVehicule emp = cvVehiculeJpaController.findCvVehicule(Integer.parseInt(value));
         //System.out.println("Employe : "+emp);
         return emp;
       } catch (Exception ex) {
           //ex.printStackTrace(System.err);
       }
        return null;
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object value) {
        //System.out.println("value getAsString"+value);
        if(value!=null && value instanceof CvVehicule){
            return String.valueOf(((CvVehicule)value).getIdvehicule());
        }
        return null;
    }

    
    
}
